#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Collections;
using Gizmox.WebGUI.Common.Resources;
using TVC.Layout;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;
using BUS;
using Gizmox.WebGUI.Common.Interfaces;

#endregion


namespace TVC.Modules.Business
{
    public partial class PurchaseRequisition : ModuleParent, IHostedApplication
    {
        //int idAllowEditLanguage = 1;
        int idAddNew = 174;
        int idEdit = 175;
        int idDelete = 176;
        int idPrint = 177;
        int idToExcel = 260;

        bool _isCalculate = true;
        string strAction = "";
        string _oldReqRef = string.Empty,
            _oldBudget = string.Empty;
        int _oldYear = 0,
            _otherRef = 0;

        public PurchaseRequisition()
        {
            InitializeComponent();
            _strType = "Requisition";
            _dgvList = dgvRequisition;
            _dgvFilter = gridFilter1;
        }

        public void InitializeApplication()
        {
        }

        //public void AddNew()
        //{

        //}

        public void SetObject(object obj)
        {
        }

        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Add New", "New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idAddNew) && IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Save", "Save", new IconResourceHandle("Save.png"), "S", false));
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Copy", "Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Edit", "Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idDelete)) objElements.Add(new HostedToolBarButton("Delete", "Delete", new IconResourceHandle("Delete.png"), "X"));

            objElements.Add(new HostedToolBarButton("Skip", "Skip", new IconResourceHandle("Reject.png"), "K", false));
            if (IsPermis(idToExcel)) objElements.Add(new HostedToolBarButton("To Excel", "To Excel", new IconResourceHandle("Excel.png"), "P"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }

        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                strAction = (string)objButton.Tag;

                BUS.PurchaseRequisitionControl ctr = new BUS.PurchaseRequisitionControl();
                switch (strAction)
                {
                    case "C":
                        AddNew(txtReqRef);
                        // txtSystemRef.Text = "";
                        break;
                    case "A":
                        editRecord(txtSystemRef);
                        break;
                    case "S":
                        var dt = dgvFiles.DataSource as DataTable;
                        dt.AcceptChanges();
                        saveRecord(txtSystemRef);
                        break;
                    case "O":
                        copy(txtReqRef);
                        txtSystemRef.Text = "";
                        _oldReqRef = string.Empty;
                        break;
                    case "X":
                        delete(txtSystemRef);
                        break;
                    case "K":
                        var dtX = dgvFiles.DataSource as DataTable;
                        dtX.RejectChanges();
                        skip();
                        break;
                    case "P":
                        export2Excel();
                        break;
                    case "R":
                        reloadList();
                        break;
                }
                if (sErr == "") ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void PurchaseRequisition_Load(object sender, EventArgs e)
        {
            //LoadList();
            SetLabel();
            LoadCombo();
            refreshForm("");
            enableForm(false);
        }

        private void SetLabel()
        {
            string otherBUS = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") otherBUS = "HL";
            lbApprovedHL.Text = string.Format("Budget Approved ({0})", GetMainForm().PODInfo.Business_ID);
            lbRemainHL.Text = string.Format("Remaining Budget ({0})", GetMainForm().PODInfo.Business_ID);
            lblAmountHV.Text = "Amount " + otherBUS;
            lblOtherAmountHV.Text = "Other Amt " + otherBUS;

            dgvFiles.Columns[3].HeaderText = "Amount " + otherBUS;
            dgvFiles.Columns[4].HeaderText = "Other Amt " + otherBUS;
        }

        private void LoadCombo()
        {
            DataTable dtb = new DataTable();

            dtb.Columns.Add("ID", typeof(string));
            dtb.Columns.Add("Name", typeof(string));
            dtb.Rows.Add("PR", "Purchasing Requisition");
            dtb.Rows.Add("SR", "Service Requisition");
            dtb.Rows.Add("CR", "Contract Requisition");
            dtb.Rows.Add("TR", "Training Requisition");

            cboRequisitionType.DataSource = dtb;
            cboRequisitionType.DisplayMember = "Name";
            cboRequisitionType.ValueMember = "ID";
            ////////////////////
            BUS.BudgetsControl ctrcontr = new BUS.BudgetsControl();

            cboBudgetCode.DisplayMember = "BudgetCode";
            cboBudgetCode.ValueMember = "BudgetCode";

            cboBudgetCode.DataSource = ctrcontr.GetShortAll(GetMainForm().PODInfo.Business_ID, ref sErr);

            btBudget.Tag = ctrcontr.GetAll(GetMainForm().PODInfo.Business_ID, ref sErr);
            ///////////
            BUS.VENDORControl ctrVD = new BUS.VENDORControl();
            DataTable dtbVD = ctrVD.GetAll_VENDOR(ref sErr);

            cboSupplier.MainForm = GetMainForm();
            cboSupplier.Lookup = "cboVD";

            cboSupplier.DisplayMember = "VendorCode";
            cboSupplier.ValueMember = "VendorCode";
            cboSupplier.DataSource = dtbVD;
            ///////////

            cboSupplierName.MainForm = GetMainForm();
            cboSupplierName.Lookup = "cboVD";

            cboSupplierName.DisplayMember = "VendorName";
            cboSupplierName.ValueMember = "VendorName";
            cboSupplierName.DataSource = dtbVD;

            ////////////
            //////////change DB

            BUS.SSRFANVControl ctrOrgan = new BUS.SSRFANVControl();
            DataTable dtExp = ctrOrgan.GetAll_SSRFANVBU("T5", GetMainForm().SUNDB, ref sErr, MainForm.HLConnect);

            cboEmpCode.MainForm = GetMainForm();
            cboEmpCode.Lookup = "SSRFANV";

            cboEmpCode.DisplayMember = "CODE";
            cboEmpCode.ValueMember = "CODE";
            cboEmpCode.DataSource = dtExp;

            ///////////
            ////////////////////
            BUS.ContractControl ctrcontract = new BUS.ContractControl();
            DataTable dtbContract = ctrcontract.GetAll(GetMainForm().PODInfo.Business_ID, ref sErr);

            cboContractPO.DisplayMember = "Contract";
            cboContractPO.ValueMember = "Contract";
            cboContractPO.MainForm = GetMainForm();
            cboContractPO.Lookup = "cboCTPO";

            cboContractPO.DataSource = dtbContract;
            ///////////

        }
        private void Rebind()
        {
            gridFilter1.btnOK_Click(null, null);
        }

        private void gridFilter1_GridFiterEvent(string strFilter, int year)
        {
            string sErr = "";
            BUS.PurchaseRequisitionControl ctrExc = new BUS.PurchaseRequisitionControl();
            //if (strFilter.Trim() != "" && year > 0)
            //    strFilter = strFilter;// + " and year(IssueDate) = " + year.ToString();
            //else if (strFilter.Trim() == "" && year > 0)
            //    strFilter = strFilter + " year(IssueDate) = " + year.ToString();

            //strFilter = strFilter;
            FormatDate();
            DataTable dtb = ctrExc.GetCond(GetMainForm().PODInfo.Business_ID, strFilter, ref sErr);
            if (!string.IsNullOrEmpty(gridFilter1.SortField))
            {
                dtb.DefaultView.Sort = gridFilter1.SortField + " " + gridFilter1.Direction;
            }
            dgvRequisition.SuspendLayout();

            bisRequisition.DataSource = dtb;
            dgvRequisition.ResumeLayout(true);
            if (dtb.Rows.Count > 0)
            {
                try
                {
                    txtTotalAmount.Value = Convert.ToDecimal(dtb.Compute("SUM(Amt)", ""));
                    txtTotalOtherAmount.Value = Convert.ToDecimal(dtb.Compute("SUM(OtherAmt)", ""));// decimal.TryParse(dtbSum.Rows[0]["OtherAmt"].ToString(), out temp) ? decimal.Parse(dtbSum.Rows[0]["OtherAmt"].ToString()) : 0;
                }
                catch { }
            }
        }

        #region .::| Override Functions |::.
        protected override ErrorStatus validateForm(ref string sErr)
        {
            BUS.PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();
            ErrorStatus result = ErrorStatus.SUCCESS;
            sErr = "";
            sErr = CheckCurrency();
            string sWarn = "";
            errProvider.SetError(txtReqRef, "");
            errProvider.SetError(txtRequisitionDate, "");
            errProvider.SetError(cboBudgetCode, "");
            errProvider.SetError(txtBudgetYear, "");
            gridFilter1.Focus();

            if (txtReqRef.Text.Trim() == "")
            {
                errProvider.SetError(txtReqRef, "Requisition Reference can't be blank.");
                sErr += "ERROR: Requisition Reference can't be blank!\n";
                // txtReqRef.Focus();
            }
            if (txtBudgetYear.Value < 1900)
            {
                errProvider.SetError(txtBudgetYear, "Please enter budget year!");
                sErr += "ERROR: Please enter budget year!\n";
                // txtBudgetYear.Focus();
            }
            if (txtRequisitionDate.Text.Trim() == "")
            {
                errProvider.SetError(txtRequisitionDate, "Requisition Date can't be blank.");
                sErr += "ERROR: Requisition Date can't be blank!\n";
                //txtRequisitionDate.Focus();
            }

            if (cboBudgetCode.SelectedValue + "" == "")
            {
                errProvider.SetError(cboBudgetCode, "Please enter budget code!");
                sErr += "ERROR: Budget code can't be blank!\n";
                //cboBudgetCode.Focus();
            }

            BUS.BudgetsControl bugCtr = new BudgetsControl();
            if (!bugCtr.IsExist(GetMainForm().PODInfo.Business_ID, cboBudgetCode.SelectedValue + "", Convert.ToInt32(txtBudgetYear.Value)))
            {
                errProvider.SetError(cboBudgetCode, "Please check budget code!");
                sErr += "ERROR: Budget code do not exists!\n";
            }

            if (!string.IsNullOrEmpty(_oldReqRef) && _oldReqRef != txtReqRef.Text)
            {
                var oBusId = "HV";
                if (GetMainForm().PODInfo.Business_ID == "HV")
                {
                    oBusId = "HL";
                }
                DataTable dt = dgvFiles.DataSource as DataTable;
                foreach (DataRow r in dt.Rows)
                {
                    if (ctr.IsExist_ReqRef(GetMainForm().PODInfo.Business_ID, txtReqRef.Text + "", Convert.ToInt32(r["aYear"] == DBNull.Value ? 0 : r["aYear"]), Convert.ToInt32(r["Reference"] == DBNull.Value ? 0 : r["Reference"])))
                    {
                        sErr += "ERROR: " + GetMainForm().PODInfo.Business_ID + " - Requisition Ref (" + txtReqRef.Text + ")  in Year (" + r["aYear"] + ") already exists, please check!";
                        break;
                    }
                    else if (ctr.IsExist_ReqRef(oBusId, txtReqRef.Text + "", Convert.ToInt32(r["aYear"] == DBNull.Value ? 0 : r["aYear"]), Convert.ToInt32(r["OReference"] == DBNull.Value ? 0 : r["OReference"])))
                    {
                        sErr += "ERROR: " + oBusId + " - Requisition Ref (" + txtReqRef.Text + ")  in Year (" + r["aYear"] + ") already exists, please check!";
                        break;
                    }
                }
                if (ckbShared.Checked)
                {
                    int year = Convert.ToInt32(txtBudgetYear.Value);
                    if (ctr.IsExist_ReqRef(oBusId, txtReqRef.Text + "", year, _otherRef))
                    {
                        sErr += "ERROR: " + oBusId + " - Requisition Ref (" + txtReqRef.Text + ")  in Year (" + year + ") already exists, please check!";

                    }
                }
            }

            sWarn = CheckBudgetValue();

            if (sErr != "") result = ErrorStatus.ERROR;
            else if (sWarn != "") result = ErrorStatus.WARNING;

            sErr = string.Format("{0}{1}", sErr, sWarn);

            return result;
        }
        protected override ErrorStatus beforeUpdate(ref string sErr)
        {
            string oBus = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") oBus = "HL";
            PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();
            int year = Convert.ToInt32(txtBudgetYear.Value);
            int sysRef = int.Parse(txtSystemRef.Text.ToString() == "" ? "0" : txtSystemRef.Text.ToString());
            bool res = ctr.IsExist_ReqRef(GetMainForm().PODInfo.Business_ID, txtReqRef.Text, year, sysRef);

            if (res) sErr = GetMainForm().PODInfo.Business_ID + " - Requisition Ref. (" + txtReqRef.Text + ")  in Year (" + year + ") already exists, please check!";
            if (ckbShared.Checked)
            {
                res = ctr.IsExist_ReqRef(oBus, txtReqRef.Text, year, sysRef);
                if (res)
                {
                    if (!string.IsNullOrEmpty(sErr)) sErr += "\n";
                    sErr += oBus + " - Requisition Ref. (" + txtReqRef.Text + ")  in Year (" + year + ") already exists, please check!";
                }
            }
            return string.IsNullOrEmpty(sErr) ? ErrorStatus.SUCCESS : ErrorStatus.ERROR;
        }
        protected override bool checkExists()
        {
            string oBus = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") oBus = "HL";
            PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();
            int year = Convert.ToInt32(txtBudgetYear.Value);
            int sysRef = int.Parse(txtSystemRef.Text.ToString() == "" ? "0" : txtSystemRef.Text.ToString());
            bool res = ctr.IsExist_ReqRef(GetMainForm().PODInfo.Business_ID, txtReqRef.Text, year, sysRef);

            if (res) _strsErrcheckExists = GetMainForm().PODInfo.Business_ID + " - Requisition Ref. (" + txtReqRef.Text + ")  in Year (" + year + ") already exists, please check!";
            if (ckbShared.Checked)
            {
                res = ctr.IsExist_ReqRef(oBus, txtReqRef.Text, year, sysRef);
                if (res)
                {
                    if (!string.IsNullOrEmpty(_strsErrcheckExists)) _strsErrcheckExists += "\n";
                    _strsErrcheckExists += oBus + " - Requisition Ref. (" + txtReqRef.Text + ")  in Year (" + year + ") already exists, please check!";
                }
            }
            return res;

        }

        protected override string addRecord(bool isDraft = false)
        {
            string sErr = "";
            int intRef = 0;
            PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();
            ctr.BeginTransaction(ref sErr);
            try
            {
                DTO.PurchaseRequisitionInfo info = GetData();


                intRef = ctr.Add(GetMainForm().PODInfo.Business_ID, info, ref sErr);
                if (sErr == "") sErr = AddDetails(ctr, info);

            }
            catch (Exception ex) { sErr = ex.Message; }
            finally
            {
                if (sErr == "")
                {
                    ctr.CommitTransaction(ref sErr);
                    txtSystemRef.Text = intRef.ToString();
                }
                else ctr.RollbackTransaction(ref sErr);
            }

            return sErr;
        }
        protected override string updateRecord(bool isDraft = false)
        {
            string sErr = "";
            PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();
            ctr.BeginTransaction(ref sErr);
            try
            {
                DTO.PurchaseRequisitionInfo info = GetData();

                if (sErr == "") sErr = ctr.Update(GetMainForm().PODInfo.Business_ID, info);
                if (sErr == "") sErr = AddDetails(ctr, info);

            }
            catch (Exception ex) { sErr = ex.Message; }
            finally
            {
                if (sErr == "")
                {
                    ctr.CommitTransaction(ref sErr);

                }
                else ctr.RollbackTransaction(ref sErr);
            }
            return sErr;
        }
        protected override string delRecord()
        {
            PurchaseRequisitionControl ctr = new PurchaseRequisitionControl();

            int Reference = int.Parse(txtSystemRef.Text.ToString() == "" ? "0" : txtSystemRef.Text.ToString());
            return ctr.Delete(GetMainForm().PODInfo.Business_ID, Reference);
        }

        protected override void afterUpdate()
        {
            LoadTotal();
            string other = "HV";
            int year = Convert.ToInt32(txtBudgetYear.Value);
            if (GetMainForm().PODInfo.Business_ID == "HV") other = "HL";
            string code = cboBudgetCode.SelectedValue + "";
            UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, code, year);
            if (ckbShared.Checked)
            {
                UpdateBudgetTotal(other, code, year);
            }
            if (!string.IsNullOrEmpty(_oldBudget) && (_oldBudget != cboContractPO.Value + "" || year != _oldYear))
            {
                UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, _oldBudget, _oldYear);
                if (ckbShared.Checked)
                {
                    UpdateBudgetTotal(other, code, year);
                }
            }
        }
        protected override void afterAddNew()
        {
            LoadTotal();
            string other = "HV";
            int year = Convert.ToInt32(txtBudgetYear.Value);
            if (GetMainForm().PODInfo.Business_ID == "HV") other = "HL";
            string code = cboBudgetCode.SelectedValue + "";
            UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, code, year);
            if (ckbShared.Checked)
            {
                UpdateBudgetTotal(other, code, year);
            }
            if (!string.IsNullOrEmpty(_oldBudget) && (_oldBudget != cboContractPO.Value + "" || year != _oldYear))
            {
                UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, _oldBudget, _oldYear);
                if (ckbShared.Checked)
                {
                    UpdateBudgetTotal(other, code, year);
                }
            }

        }
        protected override void afterDelete()
        {
            LoadTotal();
            string other = "HV";
            int year = Convert.ToInt32(txtBudgetYear.Value);
            if (GetMainForm().PODInfo.Business_ID == "HV") other = "HL";
            string code = cboBudgetCode.SelectedValue + "";
            UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, code, year);
            if (ckbShared.Checked)
            {
                UpdateBudgetTotal(other, code, year);
            }
            if (!string.IsNullOrEmpty(_oldBudget) && (_oldBudget != cboContractPO.Value + "" || year != _oldYear))
            {
                UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, _oldBudget, _oldYear);
                if (ckbShared.Checked)
                {
                    UpdateBudgetTotal(other, code, year);
                }
            }
        }

        protected override void refreshForm(string str)
        {
            _isCalculate = false;
            _oldReqRef = str;
            _otherRef = 0;
            gbPrimary.SuspendLayout();
            txtReqRef.Text = "";
            txtSystemRef.Text = "";
            cboRequisitionType.Text = "";
            txtRequisitionDate.Value = DateTime.MinValue;
            txtBudgetYear.Value = DateTime.Today.Year;
            txtRequisitionDate.Text = "";
            cboBudgetCode.SelectedValue = "";
            txtDepartment.Text = "";
            txtDescription.Text = "";
            cboSupplier.Value = "";
            cboSupplierName.Value = "";
            cboEmpCode.Value = "";
            ckbShared.Checked = false;
            txtAmount.Value = 0;
            txtOtherAmount.Value = 0;
            txtCurrency.Text = "";
            txtRate.Value = 0;
            txtRemark1.Text = "";
            txtRemark2.Text = "";
            txtRemark3.Text = "";
            txtAmountHV.Value = 0;
            txtOtherAmontHV.Value = 0;
            cboContractPO.Value = "";
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[] {new DataColumn("aYear",typeof(int)),
                new DataColumn("Amt",typeof(decimal)),
                new DataColumn("OtherAmt",typeof(decimal)),
                new DataColumn("AmtOther",typeof(decimal)),
                new DataColumn("OAmtOther",typeof(decimal)),});
            dgvFiles.DataSource = dt;
            _oldYear = 0;
            _oldBudget = string.Empty;
            gbPrimary.ResumeLayout(true);
            _isCalculate = true;
        }
        protected override void enableForm(bool val)
        {
            gbPrimary.SuspendLayout();
            txtReqRef.Enabled = val;
            //txtSystemRef.Enabled = val;
            cboRequisitionType.Enabled = val;
            txtBudgetYear.Enabled = val;
            txtRequisitionDate.Enabled = val;
            cboBudgetCode.Enabled = val;
            txtDepartment.Enabled = val;
            txtDescription.Enabled = val;
            cboSupplier.Enabled = val;
            cboSupplierName.Enabled = val;
            cboEmpCode.Enabled = val;
            ckbShared.Enabled = val;
            txtAmount.Enabled = val;
            txtOtherAmount.Enabled = val;
            txtCurrency.Enabled = val;
            txtRate.Enabled = val;
            txtRemark1.Enabled = val;
            txtRemark2.Enabled = val;
            txtRemark3.Enabled = val;
            txtAmountHV.Enabled = val;
            txtOtherAmontHV.Enabled = val;
            cboContractPO.Enabled = val;
            btBudget.Enabled = val;
            //dgvFiles.EndEdit();
            dgvFiles.Enabled = val;
            //dgvFiles.AllowUserToAddRows = val;
            //dgvFiles.AllowUserToDeleteRows = val;

            if (val == false)
            {
                foreach (Control x in gbPrimary.Controls)
                {
                    if (errProvider.GetError(x) != string.Empty) errProvider.SetError(x, "");
                }
            }
            gbPrimary.ResumeLayout(true);
        }

        protected override void loadRecord(object o)
        {
            if (o is DataRowView)
            {
                DTO.PurchaseRequisitionInfo inf = new DTO.PurchaseRequisitionInfo((DataRowView)o);
                SetData(inf);
            }
        }

        #endregion

        private void SetData(DTO.PurchaseRequisitionInfo info)
        {
            _isCalculate = false;
            try
            {
                _oldReqRef = txtReqRef.Text = info.InvNo;
                txtSystemRef.Text = info.Reference.ToString();
                cboRequisitionType.SelectedValue = info.PymtRef;
                txtBudgetYear.Value = _oldYear = info.aYear;
                txtRequisitionDate.Text = (info.IssueDate == DateTime.MinValue ? "" : info.IssueDate.ToString("dd/MM/yyyy"));
                cboBudgetCode.SelectedValue = _oldBudget = info.Contract;
                txtDepartment.Text = info.Department;
                txtDescription.Text = info.Description;
                cboSupplier.Value = info.VendorCode;
                cboSupplierName.Value = info.Creditor;
                cboEmpCode.Value = info.Receiver;
                ckbShared.Checked = bool.Parse(info.Mark.ToString() == "1" ? "true" : "false");
                txtAmount.Value = decimal.Parse(info.Amt.ToString());
                txtOtherAmount.Value = decimal.Parse(info.OtherAmt.ToString());
                txtCurrency.Text = info.Currency;
                txtRate.Value = decimal.Parse(info.CvtRate.ToString());
                txtRemark1.Text = info.Remark1;
                txtRemark2.Text = info.Remark2;
                txtRemark3.Text = info.Remark3;

                cboContractPO.Value = info.RealContract;
                SetAmountOther(info);
                LoadRelationGrid(info);
                LoadTotal();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, false);
            }
            finally { _isCalculate = true; }
            BudgetChage();

        }
        void UpdateBudgetTotal(string busId, string code, int year)
        {
            BUS.BudgetsControl budCtr = new BUS.BudgetsControl();
            budCtr.updateTotal(busId, code, year, ref sErr);
        }
        private void LoadTotal()
        {
            sErr = "";
            string other = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") other = "HL";
            string code = cboBudgetCode.SelectedValue + "";
            int year = Convert.ToInt32(txtBudgetYear.Value);
            BUS.PurchaseRequisitionControl ctr = new BUS.PurchaseRequisitionControl();
            BUS.BudgetsControl budCtr = new BUS.BudgetsControl();
            DTO.BudgetsInfo inf = budCtr.Get_Budget(GetMainForm().PODInfo.Business_ID, code, year, ref sErr);
            DTO.BudgetsInfo otherBudInf = budCtr.Get_Budget(other, code, year, ref sErr);


            txtBudgetApproved.Value = Convert.ToDecimal(inf.LimitAmt);
            txtRemainingBudget.Value = txtBudgetApproved.Value - ctr.getBudgetTotalAmt(GetMainForm().PODInfo.Business_ID, code, year, ref sErr);
            txtSharedBudget.Value = txtBudgetApproved.Value + Convert.ToDecimal(otherBudInf.LimitAmt);
            txtSharedRemaining.Value = txtSharedBudget.Value - txtBudgetApproved.Value + txtRemainingBudget.Value - ctr.getBudgetTotalAmt(other, code, year, ref sErr);

            //UpdateTotalContract(_oldBudget);
        }

        private void LoadRelationGrid(DTO.PurchaseRequisitionInfo info)
        {
            string sErr = "";
            BUS.PurchaseRequisitionControl ctr = new BUS.PurchaseRequisitionControl();
            DataTable dt = ctr.getOtherPurchaseByRef(GetMainForm().PODInfo.Business_ID, info.InvNo, info.aYear, ref sErr);
            dgvFiles.DataSource = dt;
        }

        private void SetAmountOther(DTO.PurchaseRequisitionInfo info)
        {
            sErr = "";
            string busId = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") busId = "HL";
            BUS.PurchaseRequisitionControl ctr = new BUS.PurchaseRequisitionControl();
            DataTable dt = ctr.getAmts(busId, info.InvNo, info.aYear, ref sErr);
            if (sErr == "" && dt.Rows.Count == 1)
            {
                txtAmountHV.Value = Convert.ToDecimal(dt.Rows[0]["Amt"]);
                txtOtherAmontHV.Value = Convert.ToDecimal(dt.Rows[0]["OtherAmt"]);
                _otherRef = Convert.ToInt32(dt.Rows[0]["Reference"]);
            }
            else
            {
                txtAmountHV.Value = 0;
                txtOtherAmontHV.Value = 0;
                _otherRef = 0;
            }
        }

        private void SetBudget(DTO.BudgetsInfo info)
        {
            txtBudgetCode.Text = info.Contract;
            txtbgYear.Text = info.aYear.ToString();
            txtbgGroup.Text = info.BudgetGroup;
            txtLimitAmt.Value = Convert.ToDecimal(info.LimitAmt);
            //txtTotalRequisition.Value = decimal.Parse(info.CummulativeAmt.ToString());
            txtBdDescription.Text = info.Desc;
            //txtRemaining.Value = decimal.Parse(info.RemainingAmt.ToString());
            ckbShareBg.Checked = bool.Parse(info.SharedBudget.ToString() == "1" ? "true" : "false");
            txtValue1.Value = Convert.ToDecimal(info.LimitAmtV1);
            txtDate1.Value = info.Date1;
            txtNote11.Text = info.Desc1V1;
            txtNote21.Text = info.Desc2V1;
            txtValue2.Value = Convert.ToDecimal(info.LimitAmtV2);
            txtDate2.Value = info.Date2;
            txtNote12.Text = info.Desc1V2;
            txtNote22.Text = info.Desc2V2;
            txtValue3.Value = Convert.ToDecimal(info.LimitAmtV3);
            txtDate3.Value = info.Date3;
            txtNote13.Text = info.Desc1V3;
            txtNote23.Text = info.Desc2V3;
            txtValue4.Value = Convert.ToDecimal(info.LimitAmtV4);
            txtDate4.Value = info.Date4;
            txtNote14.Text = info.Desc1V4;
            txtNote24.Text = info.Desc2V4;
            txtValue5.Value = Convert.ToDecimal(info.LimitAmtV5);
            txtDate5.Value = info.Date5;
            txtNote15.Text = info.Desc1V5;
            txtNote25.Text = info.Desc2V5;
            txtBudgetHolder.Text = info.ContractHolder;
            txtBgDep.Text = info.Department;
            txtEmp.Text = info.Employee;
        }

        private DTO.PurchaseRequisitionInfo GetData()
        {
            return new DTO.PurchaseRequisitionInfo(
                int.Parse(txtSystemRef.Text.ToString() == "" ? "0" : txtSystemRef.Text.ToString()),
                txtReqRef.Text,
                cboSupplierName.Value.ToString(),
                "",//String OurRef,
                txtRequisitionDate.Value,
                DateTime.MinValue,//DateTime ReceiptDate,
                double.Parse(txtAmount.Value.ToString()),//Double Amt,
                double.Parse(txtOtherAmount.Value.ToString()),//Double OtherAmt,
                txtCurrency.Text,
                cboRequisitionType.SelectedValue + "",
                DateTime.MinValue,//DateTime PaidDate,
                0,//Int32 PaymentTerm,
                DateTime.MinValue,//DateTime DueDate,
                txtDescription.Text,
                cboBudgetCode.SelectedValue + "",
                DateTime.MinValue,//DateTime DeliveryDate,
                DateTime.MinValue,//DateTime ReturnedDate,
                txtDepartment.Text,
                txtRemark1.Text,
                txtRemark2.Text,
                txtRemark3.Text,
                short.Parse(ckbShared.Checked ? "1" : "0"),//Int16 Mark,
                "",//String TransMitRef,
                DateTime.MinValue,//DateTime TransMitDate,
                short.Parse("0"),//Int16 MarkTrm,
                "",//String TransMitStat,
                cboEmpCode.Value + "",// String Receiver,
                cboSupplier.Value + "",// String VendorCode,
                short.Parse("0"),//Int16 LineNo,
                double.Parse(txtRate.Value.ToString()),//Double CvtRate,
                "",//String ReturnRef,
                int.Parse(txtBudgetYear.Text.ToString() == "" ? "0" : txtBudgetYear.Text.ToString()),//Int32 aYear,
                cboContractPO.Value + "",//String RealContract,
                GetMainForm().PODInfo.USER_ID, //String CreatedBy,
                GetMainForm().PODInfo.USER_ID, //String ModifiedBy,
                DateTime.Now,//DateTime CreatedDate,
                DateTime.Now//DateTime ModifiedDate
                );
        }

        private string CheckBudgetValue()
        {
            string sErr = "";
            string otherBusId = GetMainForm().PODInfo.Business_ID == "HL" ? "HV" : "HL";
            string code = cboBudgetCode.SelectedValue + "";
            int year = Convert.ToInt32(txtBudgetYear.Value);
            int refer = 0;
            if (txtSystemRef.Text != "") refer = Convert.ToInt32(txtSystemRef.Text);

            BUS.PurchaseRequisitionControl purCtr = new BUS.PurchaseRequisitionControl();
            decimal totalCurrentAmt = purCtr.getBudgetTotalAmt(GetMainForm().PODInfo.Business_ID, code, year, ref sErr, refer);
            decimal totalOtherAmt = purCtr.getBudgetTotalAmt(otherBusId, code, year, ref sErr);

            decimal totalCurrentGroupAmt = purCtr.getBudgetGroupTotalAmt(GetMainForm().PODInfo.Business_ID, code, year, ref sErr, refer);
            decimal totalOtherGroupAmt = purCtr.getBudgetGroupTotalAmt(otherBusId, code, year, ref sErr);

            BUS.BudgetsControl ctr = new BUS.BudgetsControl();
            decimal totalCurrentBudgetAmt = ctr.getTotalAmt(GetMainForm().PODInfo.Business_ID, code, year, ref sErr);
            decimal totalOtherBudgetAmt = ctr.getTotalAmt(otherBusId, code, year, ref sErr);

            decimal totalCurrentBudgetGroupAmt = ctr.getTotalGroupAmt(GetMainForm().PODInfo.Business_ID, code, year, ref sErr);
            decimal totalOtherBudgetGroupAmt = ctr.getTotalGroupAmt(otherBusId, code, year, ref sErr);

            if (ckbShared.Checked)
            {
                if (totalCurrentAmt + txtAmount.Value + totalOtherAmt > totalCurrentBudgetAmt + totalOtherBudgetAmt)
                {
                    sErr = string.Format("WARNING: The total Budget is overpaid {0:N2}. Please check!\n", totalCurrentAmt + txtAmount.Value + totalOtherAmt - (totalCurrentBudgetAmt + totalOtherBudgetAmt));
                }
                else if (totalCurrentAmt + txtAmount.Value > totalCurrentBudgetAmt)
                {
                    sErr = string.Format("WARNING: The total Budget is overpaid {0:N2}. The total shared Budget is over though!\n", totalCurrentAmt + txtAmount.Value - totalCurrentBudgetAmt);
                }

                if (totalCurrentGroupAmt + txtAmount.Value + totalOtherAmt > totalCurrentBudgetGroupAmt + totalOtherBudgetGroupAmt)
                {
                    sErr += string.Format("WARNING: The total Budget Group is overpaid {0:N2}. Please check!\n", totalCurrentGroupAmt + txtAmount.Value + totalOtherAmt - (totalCurrentBudgetGroupAmt + totalOtherBudgetGroupAmt));
                }
                else if (totalCurrentGroupAmt + txtAmount.Value > totalCurrentBudgetGroupAmt)
                {
                    sErr += string.Format("WARNING: The total Budget Group is overpaid {0:N2}. The total shared Budget Group is over though!\n", totalCurrentGroupAmt + txtAmount.Value - totalCurrentBudgetGroupAmt);
                }

                warnProvider.SetError(txtAmount, sErr);

            }
            else
            {
                if (totalCurrentAmt + txtAmount.Value > totalCurrentBudgetAmt)
                {
                    sErr = string.Format("WARNING: The Budget is overpaid {0:N2}. Please check!\n", totalCurrentAmt + txtAmount.Value - totalCurrentBudgetAmt);
                }

                if (totalCurrentGroupAmt + txtAmount.Value > totalCurrentBudgetGroupAmt)
                {
                    sErr += string.Format("WARNING: The Budget Group is overpaid {0:N2}. Please check!\n", totalCurrentGroupAmt + txtAmount.Value - totalCurrentBudgetGroupAmt);
                }

                warnProvider.SetError(txtAmount, sErr);
            }
            return sErr;
        }

        //private string DeleteDetails(BUS.PurchaseRequisitionControl ctr, DTO.PurchaseRequisitionInfo info)
        //{
        //    return ctr.DeleteRef(GetMainForm().PODInfo.Business_ID, info.InvNo, info.aYear);
        //}

        private string AddDetails(BUS.PurchaseRequisitionControl ctr, DTO.PurchaseRequisitionInfo info)
        {
            string sErr = "";
            double amount = 0;
            double oAmt = 0;
            string otherBus = "HV";
            if (GetMainForm().PODInfo.Business_ID == "HV") otherBus = "HL";
            if (ckbShared.Checked)
            {
                amount = Convert.ToDouble(txtAmountHV.Value);
                oAmt = Convert.ToDouble(txtOtherAmontHV.Value);

                if (amount > 0)
                {
                    info.Amt = amount;
                    info.OtherAmt = oAmt;
                    info.CvtRate = info.OtherAmt / info.Amt;
                    if (_otherRef <= 0) _otherRef = ctr.Add(otherBus, info, ref sErr);
                    else
                    {
                        var oInf = new DTO.PurchaseRequisitionInfo(info);
                        oInf.Reference = _otherRef;
                        sErr = ctr.updateAmt(otherBus, oInf);
                    }
                    //ctr.insertUpdateAmt(otherBus, info, ref sErr);
                }
            }

            if (sErr != "") return sErr;
            DataTable dt = dgvFiles.DataSource as DataTable;

            if (dt != null)
            {
                foreach (DataRow r in dt.Rows)
                {
                    if (sErr != "") return sErr;

                    try
                    {
                        if (Regex.IsMatch(r["aYear"].ToString(), "^[0-9]+$"))
                        {
                            info.Reference = Convert.ToInt32(r["Reference"] == DBNull.Value ? 0 : r["Reference"]);
                            info.aYear = Convert.ToInt32(r["aYear"]);
                            if (r["Amt"] != DBNull.Value) amount = Convert.ToDouble(r["Amt"]);
                            else amount = 0;
                            if (r["OtherAmt"] != DBNull.Value) oAmt = Convert.ToDouble(r["OtherAmt"]);
                            else oAmt = 0;
                            if (amount > 0)
                            {
                                info.Amt = amount;
                                info.OtherAmt = oAmt;
                                info.CvtRate = info.OtherAmt / info.Amt;
                                if (info.Reference > 0)
                                {
                                    sErr = ctr.updateAmt(GetMainForm().PODInfo.Business_ID, info);
                                }
                                else
                                {
                                    r["Reference"] = info.Reference = ctr.Add(GetMainForm().PODInfo.Business_ID, info, ref sErr);
                                }
                                UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, info.Contract, info.aYear);
                                if (!string.IsNullOrEmpty(_oldBudget) && (_oldBudget != cboContractPO.Value + "" || info.aYear != _oldYear))
                                {
                                    UpdateBudgetTotal(GetMainForm().PODInfo.Business_ID, _oldBudget, _oldYear);
                                }
                                //ctr.insertUpdateAmt(GetMainForm().PODInfo.Business_ID, info, ref sErr);
                            }
                            if (sErr != "") return sErr;
                            if (true)//ckbShared.Checked)
                            {
                                info.Reference = Convert.ToInt32(r["OReference"] == DBNull.Value ? 0 : r["OReference"]);
                                if (r["AmtOther"] != DBNull.Value) amount = Convert.ToDouble(r["AmtOther"]);
                                else amount = 0;
                                if (r["OAmtOther"] != DBNull.Value) oAmt = Convert.ToDouble(r["OAmtOther"]);
                                else oAmt = 0;
                                if (amount > 0)
                                {
                                    info.Amt = amount;
                                    info.OtherAmt = oAmt;
                                    info.CvtRate = info.OtherAmt / info.Amt;

                                    if (info.Reference > 0)
                                    {
                                        sErr = ctr.updateAmt(otherBus, info);
                                    }
                                    else
                                    {
                                        r["OReference"] = info.Reference = ctr.Add(otherBus, info, ref sErr);
                                    }
                                    UpdateBudgetTotal(otherBus, info.Contract, info.aYear);
                                    if (!string.IsNullOrEmpty(_oldBudget) && (_oldBudget != cboContractPO.Value + "" || info.aYear != _oldYear))
                                    {
                                        UpdateBudgetTotal(otherBus, _oldBudget, _oldYear);
                                    }
                                    //ctr.insertUpdateAmt(otherBus, info, ref sErr);
                                }
                                if (sErr != "") return sErr;
                            }
                        }

                    }
                    catch (Exception ex) { sErr = ex.Message; }

                }
            }
            return sErr;
        }

        //private void LoadList()
        //{
        //   // GetMainForm().LoadDataTable(_strType);
        //    Rebind();
        //    layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
        //    layout.SetUpDGV(dgvRequisition);
        //    if (dgvRequisition.ShowFilterRow == true)
        //        mnuShowFilter.Checked = true;
        //}


        private void ckbShared_CheckedChanged(object sender, EventArgs e)
        {
            lblAmountHV.Visible = lblOtherAmountHV.Visible = txtOtherAmontHV.Visible = txtAmountHV.Visible = ckbShared.Checked;
        }

        private void txt_ValueChanged(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                _isCalculate = false;
                if (txtAmount.Value != 0) txtRate.Value = txtOtherAmount.Value / txtAmount.Value;
                _isCalculate = true;
            }
        }

        private void cboBudgetCode_SelectedValueChanged(object sender, EventArgs e)
        {
            string sErr = BudgetChage();

        }

        private void cboSupplier_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboSupplier.Value.ToString() != "")
            {
                cboSupplierName.Value = ((DataRowView)cboSupplier.SelectedItem)["VendorName"].ToString();
                cboSupplier.Focus();
            }
        }

        private void cboSupplierName_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboSupplierName.Value.ToString() != "" && cboSupplierName.Focus() == true)
            {
                cboSupplier.Value = ((DataRowView)cboSupplierName.SelectedItem)["VendorCode"].ToString();
            }
        }

        private void txtCurrency_TextChanged(object sender, EventArgs e)
        {
            string sErr = "";


            if (_isCalculate)
            {
                _isCalculate = false;
                BUS.PurchaseRequisitionControl ctr = new BUS.PurchaseRequisitionControl();
                txtRate.Value = ctr.getConvRate(GetMainForm().PODInfo.Business_ID, DateTime.Today, ref sErr);

                if (txtRate.Value != 0)
                {
                    txtAmount.Value = txtOtherAmount.Value / txtRate.Value;
                }
                _isCalculate = true;
                //UpdatePayableValue();
            }
        }

        private string CheckCurrency()
        {
            string sErr = "";
            if ((txtCurrency.Text == "" || txtCurrency.Text == "USD") && txtOtherAmount.Value > 0)
            {
                if (txtCurrency.Text == "")
                {
                    errProvider.SetError(txtCurrency, "Currency cannot be blank if Other Amount exists, please check!");
                    sErr += "ERROR: Currency cannot be blank if Other Amount exists, please check!\n";
                }
                else
                {
                    errProvider.SetError(txtCurrency, "Currency cannot be USD if Other Amount exists, please check!");
                    sErr += "ERROR: Currency cannot be USD if Other Amount exists, please check!\n";
                }
            }
            else errProvider.SetError(txtCurrency, "");

            if (txtOtherAmount.Value == 0 && txtCurrency.Text != "" && txtCurrency.Text != "USD")
            {
                errProvider.SetError(txtOtherAmount, " Other Amount cannot be blank if Currency exists, please check!");
                sErr += "ERROR: Other Amount cannot be blank if Currency exists, please check!\n";
            }
            else errProvider.SetError(txtOtherAmount, "");

            return sErr;
        }

        private void dgvFiles_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                bool isExists = false;

                foreach (DataGridViewRow r in dgvFiles.Rows)
                {
                    if (e.RowIndex != r.Index && r.Cells[0].Value != null && r.Cells[0].Value.ToString() == dgvFiles[0, e.RowIndex].Value.ToString())
                    { isExists = true; break; }
                }

                if (isExists)
                {
                    errProvider.SetError(dgvFiles, "Year is exists! Please check agian");
                    MessageBox.Show("Year is exists! Please check agian", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning, false);
                    ((DataRowView)dgvFiles.Rows[e.RowIndex].DataBoundItem).CancelEdit();
                }
                else if (dgvFiles[0, e.RowIndex].Value != null && Convert.ToDecimal(dgvFiles[0, e.RowIndex].Value) <= txtBudgetYear.Value)
                {
                    errProvider.SetError(dgvFiles, "Year must to be greater then " + txtBudgetYear.Value);
                    MessageBox.Show("Year must to be greater then " + txtBudgetYear.Value, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning, false);
                    ((DataRowView)dgvFiles.Rows[e.RowIndex].DataBoundItem).CancelEdit();
                }

                else errProvider.SetError(dgvFiles, "");


            }
        }

        private void txtBudgetYear_ValueChanged(object sender, EventArgs e)
        {
            string sErr = BudgetChage();
        }

        private string BudgetChage()
        {
            string sErr = "";
            if (_isCalculate)
            {
                if (cboBudgetCode.SelectedValue != null && txtBudgetYear.Value != 0)
                {
                    BUS.BudgetsControl ctrcontr = new BUS.BudgetsControl();

                    DTO.BudgetsInfo inf = ctrcontr.Get_Budget(GetMainForm().PODInfo.Business_ID, cboBudgetCode.SelectedValue + "", Convert.ToInt32(txtBudgetYear.Value), ref sErr);
                    ckbShared.Checked = ckbShared.Visible = inf.SharedBudget == 1;
                    SetBudget(inf);
                }
                else SetBudget(new DTO.BudgetsInfo());
            }
            return sErr;
        }

        private void btBudget_Click(object sender, EventArgs e)
        {
            ViewBudget();
        }

        private void ViewBudget()
        {
            Forms.frmView frm = new Forms.frmView("bgC", GetMainForm());
            DataTable dt = btBudget.Tag as DataTable;

            if (cboBudgetCode.Text != null && cboBudgetCode.Text != "")
            {
                frm.FilterRow = "  BudgetCode LIKE '" + cboBudgetCode.Text + "%'";
            }
            frm.DataSource = dt.Copy();
            frm.FormClosed += (form, args) =>
            {
                if (((Forms.frmView)form).DialogResult == DialogResult.OK)
                {
                    cboBudgetCode.SelectedValue = ((Forms.frmView)form).ReturnValue["BudgetCode"];
                    txtBudgetYear.Value = Convert.ToInt32(((Forms.frmView)form).ReturnValue["Year"]);
                }
                cboBudgetCode.Focus();
            };
            frm.ShowDialog();
            //Forms.frmView frm = new Forms.frmView("bgC", GetMainForm());
            //DataTable dt = btBudget.Tag as DataTable;
            //frm.DataSource = dt;
            //frm.FormClosed += (form, args) =>
            //{
            //    if (((Forms.frmView)form).DialogResult == DialogResult.OK)
            //    {
            //        cboBudgetCode.SelectedValue = ((Forms.frmView)form).ReturnValue["BudgetCode"];
            //        txtBudgetYear.Value = Convert.ToInt32(((Forms.frmView)form).ReturnValue["Year"]);
            //    }
            //    cboBudgetCode.Focus();
            //};
            //frm.ShowDialog();
        }

        private void txtRate_ValueChanged(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                _isCalculate = false;
                if (txtRate.Value != 0) txtAmount.Value = txtOtherAmount.Value / txtRate.Value;
                _isCalculate = true;
            }
        }

        private void txtOtherAmt_ValueChanged(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                _isCalculate = false;

                if (txtRate.Value != 0) txtAmount.Value = txtOtherAmount.Value / txtRate.Value;
                txtAmount.Focus();
                _isCalculate = true;
            }
        }

        private void txtRate_Enter(object sender, EventArgs e)
        {
            (sender as NumericUpDown).Select(0, (sender as NumericUpDown).ToString().Length);
        }

        private void dgvFiles_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            if (dgvFiles.Context is IApplicationContext)
            {
                ((IApplicationContext)dgvFiles.Context).SetFocused(dgvFiles, true);
            }
        }

        private void cboContractPO_Leave(object sender, EventArgs e)
        {
            if (cboContractPO.Text != null && cboContractPO.Text.Trim() != "")
            {
                if (cboContractPO.Value.ToString().Trim() == "")
                {
                    cboContractPO.Focus();
                    MessageBox.Show(" Please select from the list ", false);
                }
            }
        }

        private void cboEmpCode_Leave(object sender, EventArgs e)
        {
            if (cboEmpCode.Text != null && cboEmpCode.Text.Trim() != "")
            {
                if (cboEmpCode.Value.ToString().Trim() == "")
                {
                    cboEmpCode.Focus();
                    MessageBox.Show(" Please select from the list ", false);
                }
            }
        }

        private void cboSupplier_Leave(object sender, EventArgs e)
        {
            if (cboSupplier.Text != null && cboSupplier.Text.Trim() != "")
            {
                if (cboSupplier.Value.ToString().Trim() == "")
                {
                    cboSupplier.Focus();
                    MessageBox.Show(" Please select from the list ", false);
                }
            }
        }

        private void panelMaster_Click(object sender, EventArgs e)
        {

        }

        //private void cboSupplierName_Leave(object sender, EventArgs e)
        //{
        //    if (cboSupplierName.Text != null && cboSupplierName.Text.Trim() != "")
        //    {
        //        if (cboSupplierName.Value.ToString().Trim() == "")
        //        {
        //            cboSupplierName.Focus();
        //            MessageBox.Show(" Please select from the list ", false);
        //        }
        //    }
        //}

        //private void cboBudgetCode_Leave(object sender, EventArgs e)
        //{
        //if (cboBudgetCode.Text != null && cboBudgetCode.Text.Trim() != "")
        //{
        //    btBudget.Text = cboBudgetCode.Text;
        //    //if (cboBudgetCode.SelectedValue == null)
        //    //{
        //    //    cboBudgetCode.Focus();
        //    //    MessageBox.Show(" Please select from the list ", false);
        //    //}
        //}
        //}


    }
}